package cn.com.klun.step;

import cn.com.klun.tjy.base.IStep;
import cn.com.klun.tjy.dao.entity.TblTaskBasicConfig;
import cn.com.klun.tjy.dao.mapper.edit.TblStockDayInfosEditMapper;
import cn.com.klun.tjy.dao.mapper.ser.TblStockDayInfosSerMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class DistinctStockInfoTask implements IStep<ArrayList<String>>{

    private static Logger logger = LoggerFactory.getLogger(DistinctStockInfoTask.class);

    @Autowired
    private TblStockDayInfosSerMapper tblStockDayInfosSerMapper;
    @Autowired
    private TblStockDayInfosEditMapper tblStockDayInfosEditMapper;

    @Override
    public ArrayList queryTaskInfo(TblTaskBasicConfig config) {
        List<String> StoIdList = new ArrayList<>();
        StoIdList = tblStockDayInfosSerMapper.queryNeedDistinctStock();
        logger.info("查询出需要去重的股票ID，长度{}",StoIdList.size());
        return (ArrayList) StoIdList;
    }

    @Override
    public void runTask(ArrayList<String> ids) {
        try {
            logger.info("开始删除重复录入的股票信息，长度stockId{}",ids.size());
            int del = tblStockDayInfosEditMapper.del(ids);
            logger.info("完成计算股票的信息,共删除{}条数据",del);
        } catch (Exception e) {
            logger.error("处理idList长度【{}】异常，异常信息{}",ids.size(),e);
        }
    }

    @Override
    public boolean editTaskInfo(List list) {
        return false;
    }
}
